package com.deep.spring.v1;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;
import java.util.Map;

@Slf4j
@Component
public class TestServiceInjectProcessor implements BeanPostProcessor {

    @Autowired
    private ApplicationContext applicationContext;

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        log.info("TestServiceInjectProcessor postProcessBeforeInitialization bean = {}  ", bean);
        log.info("TestServiceInjectProcessor postProcessBeforeInitialization beanName = {}  ", beanName);
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        log.info("TestServiceInjectProcessor postProcessAfterInitialization bean = {}  ", bean);
        log.info("TestServiceInjectProcessor postProcessAfterInitialization beanName = {}  ", beanName);

        Class<?> targetCls = bean.getClass();
        Field[] targetFld = targetCls.getDeclaredFields();
        for (Field field : targetFld) {
            log.info("TestServiceInjectProcessor postProcessAfterInitialization field = {}  ", field);
            log.info("TestServiceInjectProcessor postProcessAfterInitialization field.getType() = {}  ", field.getType());

        }
        return bean;
    }

}